<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>平台管理系统</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="/layuiadmin/layui/css/layui.css"
	media="all">
<link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
<style type="text/css">
thead tr th {
	text-align: center !important;
}

tr td {
	text-align: center !important;
}
</style>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-form layui-card-header layuiadmin-card-header-auto">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">用户昵称</label>
								<div class="layui-input-inline">
									<input type="text" name="cNickName" placeholder="支持模糊查询"
										autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">用户账户</label>
								<div class="layui-input-inline">
									<input type="text" name="cPhone" placeholder=""
										autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">认证状态</label>
								<div class="layui-input-inline">
									<select name="status">
										<option value="">请选择</option>
										<option value="1">待审核</option>
										<option value="2">认证成功</option>
										<option value="3">认证失败</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">证件类型</label>
								<div class="layui-input-inline">
									<select name="authType">
										<option value="">请选择</option>
										<option value="1">大陆身份证</option>
										<option value="2">港澳台身份证</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-list" lay-submit
									lay-filter="LAY-app-contlist-search">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
								</button>
							</div>
						</div>
					</div>
					<div class="layui-card-body">
							<%-- 数据展示 --%>
						<table class="layui-table" lay-filter="table" id="table"></table>
						<script type="text/html" id="toolbar">
							<div class="layui-btn-container">
								<a class="layui-btn layui-btn-primary layui-btn-xs" lay-status="1" lay-event="detail">查看详情</a>
								<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
						    </div>
						</script>
					</div>
				</div>
			</div>
		</div>
	</div>

	<script src="/layuiadmin/layui/layui.js"></script>
	<script src="/js/common.js"></script>
	<script>
		layui.config({
			base : '/layuiadmin/' //静态资源所在路径
		}).extend({
			index : 'lib/index' //主入口模块
		}).use([ 'index', 'table','form' ], function() {
			var $ = layui.$, admin = layui.admin, table = layui.table,form=layui.form;
			table.render({
				elem : '.layui-table',
				url : '/customer/queryCustomerAuthen',
				page:true,
				request: {
					pageName: 'current', //页码的参数名称，默认：page
					limitName: 'size' //每页数据量的参数名，默认：limit
				},
				cols : [[
					{field:'authType', title:'认证类型',
						templet:function(row){
							if (row.authType == 1) {
								return "大陆身份证";
							} else {
								return "港澳台身份证";
							}
						}
					},
					{field:'cNickName', title:'用户昵称'},
					{field:'cPhone', title:'用户账户'},
					{field : 'realName', title : '真实姓名'},
					{field : 'sex', title : '性别',
						templet:function(row){
							if (row.sex == 1) {
								return "男";
							} else if (row.sex == 2) {
								return "女";
							} else {
								return "保密";
							}
						}
					},
					{field : 'isLongLasting', title : '证件是否长期有效',
						templet:function(row){
							if (row.isLongLasting == 1) {
								return "是";
							} else {
								return "否";
							}
						}
					},
					{field : 'linkPhone', title : '联系电话', minWidth:140},
					{field : 'parentName', title : '推荐人', minWidth:140},
					{field : 'status', title : '状态', 
						templet:function(row){
							if (row.status == 1) {
								return "待审核";
							} else if (row.status == 2) {
								return "认证成功";
							} else if (row.status == 3) {
								return "认证失败";
							}
						}
					},
					// {field : 'email', title : '邮箱', minWidth:200},
					{title:'操作', templet:'#toolbar'}
				]],
				skin : "row",
				even: true,
				size:"lg"
			});
			
			//监听搜索
		    form.on('submit(LAY-app-contlist-search)', function(data){
		      var field = data.field;
		      
		      //执行重载
		      table.reload('table', {
		        where: field
		      });
		    });
			
			//监听事件
			table.on('tool(table)', function(obj){
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
				var tr = obj.tr; //获得当前行 tr 的DOM对象
				
				var status;
				if (layEvent === 'detail') {// 详情
					window.location.href = "/customer/authenDetail?authenId="+data.id;
				} else if(layEvent === 'edit'){ //编辑
			          layer.open({
			              type: 2
			              ,title: '编辑'
			              ,content: '/customer/authenDetailEdit?authenId='+data.id
			              ,maxmin: true
			              ,area: ['550px', '550px']
			              ,btn: ['确定', '取消']
			              ,yes: function(index, layero){
			                var iframeWindow = window['layui-layer-iframe'+ index]
			                ,submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");
			                //监听提交
			                iframeWindow.layui.form.on('submit(layuiadmin-app-form-edit)', function(data){
			                  var field = data.field; //获取提交的字段             
			                  //提交 Ajax 成功后，静态更新表格中的数据
			                  $.ajax({
			    	    		url:"/custmer/editAuthenDetail",
			    	    		dataType:"json",
			    	    		data:field,
			    				type : "post",
			    				success : function(res) {
			    					if (res.status) {
			    			              obj.update({
			    			            	  realName: field.realName
			    			            	  ,linkPhone:field.linkPhone
			    			            	  ,sex:field.sex
			    			              });
			    						
			    					}
			    					layer.msg(res.desc);
			    				}
			    			  });
			    			  //数据更新
			                  form.render();
			                  layer.close(index); //关闭弹层
			                });  
			                submit.trigger('click');
			              }
			            });    	  
			      }
			});

		});
	</script>
	
</body>
</html>